<template>
	<view id="nameList">
		<view class="nameListWrap">
			<view class="vote-title">
				{{ typeName == 1 && voteDetailInfo.vote_type == 1 ? '筹备组成员公示' 
				    : typeName == 1 && voteDetailInfo.vote_type == 2 ? '工作组成员公示' 
					: typeName == 2 ? '委员候选人公示' 
					: typeName == 3 ? '业主大会投票结果公示'
					: typeName == 4 ? '业委会职位结果公示'
					: typeName == 5 ? '委托人公示' : '' }}
			</view>
			<view class="name-list" v-for="item in parationList" :key="item.id" @click="nameListDetail(item)">
				<view>
					<img style="width:116rpx;height:140rpx;" :src="item.user_coronal_photograph_img" />
				</view>
				<view>
					<view class="list-tit">{{ item.building_number }}</view>
					<view>楼号</view>
				</view>
				<view>
					<view class="list-tit">{{ item.full_name }}</view>
					<view>姓名</view>
				</view>
				<view v-if="typeName == 1">
					<view class="list-tit">{{ item.preparation_total }}</view>
					<view>票数</view>
				</view>
				<view v-if="typeName == 3">
					<view class="list-tit">{{ item.committee_member_total }}</view>
					<view>票数</view>
				</view>
				<view v-if="typeName == 4">
					<view class="list-tit">{{getVoteTotal(item)}}</view>
					<view>票数</view>
				</view>
				<view v-if="typeName == 3">
					<view class="list-tit">{{ item.members_state == 1 ? '准委员' : '准候补委员' }}</view>
					<view>结果</view>
				</view>
				<view v-if="typeName == 4">
					<view class="list-tit">{{ getVotePosition(item)}}</view>
					<view>职位</view>
				</view>

			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id : null,
				nameStr: '',
				parationList: [],
				typeName: null,
				voteDetailInfo : {},
			}
		},
		onLoad(option) {
			this.id = option.id
			this.typeName = option.typeName
		},
		onShow() {
			this.getUserList()
			this.getVoteDetailInfoById();
		},
		methods: {
			//获取表决投票类型 1.附议 2.筹备组报名
			getVoteDetailInfoById() {
				this.$requestYz.api.getVoteDetailInfo({
					id: this.id,
				}).then(res => {
					if (res.data.data.voteInfo) {
						this.voteDetailInfo = res.data.data.voteInfo;
					}
				})
			},
			getVoteTotal(userInfo) {
				let voteTotal = 0;
				if (userInfo.director && userInfo.director == 1) {
					voteTotal = voteTotal + userInfo.director_vote_total;
				}
				if (userInfo.deputy_director && userInfo.deputy_director == 1) {
					voteTotal = voteTotal + userInfo.deputy_director_vote_total;
				}
				return voteTotal;
			},
			getVotePosition(userInfo) {
				var positionName = '';
				//优先展示主任
				if (userInfo.deputy_director && userInfo.deputy_director == 1) {
					positionName = '副主任'
				}
				if (userInfo.director && userInfo.director == 1) {
					positionName = '主任';
				}
				// if(userInfo.deputy_director && userInfo.deputy_director == 1){
				// 	positionName = positionName ? positionName+',副主任' : '副主任'
				// }
				if (!positionName) {
					positionName = userInfo.members_state == 1 ? '委员' : '候补委员';
				}
				return positionName;
			},

			nameListDetail(item) {
				let items = encodeURIComponent(JSON.stringify(item))
				uni.navigateTo({
					url: './nameDetail?item=' + items
				})
			},
			//列表查询
			getUserList() {
				let request = {}
				//筹备组人员
				if (this.typeName == 1) {
					request = {
						essential_information_id: this.id,
						preparation_status: 1,
					}
				}
				//委员候选人
				if (this.typeName == 2) {
					request = {
						essential_information_id: this.id,
						committee_member_status: 1,
					}
				}
				//委员人
				if (this.typeName == 3) {
					request = {
						essential_information_id: this.id,
						selectMemberResult: 1,
					}
				}
				//业委会职位结果公示
				if (this.typeName == 4) {
					request = {
						essential_information_id: this.id,
						selectCommitteePositions: 1,
					}
				}
				//委托人公示
				if (this.typeName == 5) {
					request = {
						essential_information_id: this.id,
						selectCommitteePositions: 1,
					}
				}
				this.$requestYz.api.getOwnerAppVoteUserList(request).then(res => {
					this.parationList = res.data.data.datalist;
				})
			},
		}
	}
</script>

<style lang="scss">
	#nameList {
		background: #F4F4F4;
		min-height: 100vh;
		height: auto;

		.nameListWrap {
			.vote-title {
				font-size: 36rpx;
				font-weight: bold;
				margin: 0 auto 60rpx;
				text-align: center;
				padding-top: 40rpx;
			}

			.name-list {
				display: flex;
				width: 690rpx;
				height: 200rpx;
				background: #FFFFFF;
				border-radius: 12rpx;
				padding: 30rpx;
				margin: 20rpx auto;
				justify-content: space-around;
				align-items: center;
				text-align: center;

				.list-tit {
					font-size: 30rpx;
					font-weight: bold;
					margin-bottom: 20rpx;
				}
			}
		}
	}
</style>
